package com.xjscrm.console.service.customer.operatePlan.impl;

import com.xjscrm.common.constant.ResponseMsg;
import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.console.param.operatePlan.DeleTagKeywordDto;
import com.xjscrm.console.param.operatePlan.TagKeywordDeviceDto;
import com.xjscrm.console.param.wwCustomer.BatchDeleTagKeywordDeviceDto;
import com.xjscrm.console.service.customer.operatePlan.TagKeyWordBatchService;
import com.xjscrm.console.service.customer.operatePlan.TagKeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TagKeyWordBatchServiceImpl implements TagKeyWordBatchService {

    @Autowired
    private TagKeywordService tagKeywordService;
    @Override
    public void batchAddTagKeywordDevice(TagKeywordDeviceDto tagKeywordDeviceDto) {
        if(tagKeywordDeviceDto.getTagKeywordIds()==null||tagKeywordDeviceDto.getTagKeywordIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (Long tagKeywordId:tagKeywordDeviceDto.getTagKeywordIds()) {
            try {
                tagKeywordDeviceDto.setTagKeywordId(tagKeywordId);
                tagKeywordService.addTagKeywordDevice(tagKeywordDeviceDto);
            }catch (Exception e){
                e.printStackTrace();
            }

        }

    }

    @Override
    public void batchDeleTagKeyword(DeleTagKeywordDto deleTagKeywordDto) {
        if(deleTagKeywordDto.getIds()==null||deleTagKeywordDto.getIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }
        for (Long id:deleTagKeywordDto.getIds()) {
            try {
                deleTagKeywordDto.setId(id);
                tagKeywordService.deleTagKeyword(deleTagKeywordDto);
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }

    @Override
    public void batchDeleTagKeywordDevice(BatchDeleTagKeywordDeviceDto batchDeleTagKeywordDeviceDto) {
        if(batchDeleTagKeywordDeviceDto.getIds()==null||batchDeleTagKeywordDeviceDto.getIds().isEmpty()){
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, ResponseMsg.PARAMETER_ERROR);
        }

        for (Long id:batchDeleTagKeywordDeviceDto.getIds()) {
            try {
                batchDeleTagKeywordDeviceDto.setId(id);
                tagKeywordService.deleTagKeywordDevice(batchDeleTagKeywordDeviceDto);
            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }
}
